import com.sun.jmx.snmp.internal.SnmpOutgoingRequest;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

public class NewDateTimeAPI {
    public static void main(String[] args) {
        /**
         * java.time提供了很多api，其中两个比较重要：local（本地）；zoned（时区）
         * local（本地）
         * 创建对象：LocalDateTime.now(),LocalDateTime.of(),localDateTime.parse("2023-10-05T14:30:10")
         * 根据已有对象调整部分创建一个新的对象：dateTime.withDayOfMonth(10)
         * 获取日期对象的各部分int：getMonthValue
         * 对日期对象进行加减天数月份plusDays(1)，minusDays(1)
         * 使用时间调整器创建一个新的对象，某年，某月，某周的特定的某天with(TemporalAdjusters.lastDayOfMonth())
         * zoned（时区）比前者多了一个时区
         */

        LocalDateTime dateTime11 = LocalDateTime.of(2025,5,12,14,00,00);
        DateTimeFormatter f1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateTime12 = LocalDateTime.parse("2023-10-05 14:30:10",f1);
        System.out.println("parse方法："+dateTime12);


        // 获取当前的日期时间
//        LocalDate date = LocalDate.now();
//        LocalTime time = LocalTime.now();
//        LocalDateTime dateTime = LocalDateTime.now();
//        LocalDateTime datetime01 = dateTime.plusDays(1);
//        LocalDateTime datetime02 = dateTime.minusDays(1);
//        LocalDateTime datetime03 = dateTime.with(TemporalAdjusters.firstDayOfMonth());
//        LocalDateTime datetime04 = dateTime.with(TemporalAdjusters.lastDayOfMonth());
//
//        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日HH时mm分ss秒");
//        String formatDateTime = dateTime.format(dateTimeFormatter);
//        System.out.println("当前时间："+formatDateTime);


        //local（本地）
        // 获取当前的日期时间
        LocalDate date = LocalDate.now();
        LocalTime time = LocalTime.now();
        ZonedDateTime dateTime = ZonedDateTime.now();
        ZonedDateTime datetime01 = dateTime.plusDays(1);
        ZonedDateTime datetime02 = dateTime.minusDays(1);
        ZonedDateTime datetime03 = dateTime.with(TemporalAdjusters.firstDayOfMonth());
        ZonedDateTime datetime04 = dateTime.with(TemporalAdjusters.lastDayOfMonth());

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日HH时mm分ss秒");
        String formatDateTime = dateTime.format(dateTimeFormatter);
        System.out.println("formatDateTime："+formatDateTime+'\n'
                          +"dateTime："+dateTime+'\n'
                          +"datetime01："+datetime01+'\n'
                          +"datetime02："+datetime02+'\n'
                          +"datetime03："+datetime03+'\n'
                          +"datetime04："+datetime04+'\n');



        Month month = dateTime.getMonth();
        int month1 = dateTime.getMonthValue();
        int day = dateTime.getDayOfMonth();
        int seconds = dateTime.getSecond();
//        LocalDateTime date2 = dateTime.withDayOfMonth(10).withYear(2012);





        // zoned（时区）
        ZonedDateTime date1 = ZonedDateTime.parse("2015-12-03T10:15:30+05:30[Asia/Shanghai]");
        System.out.println("date1: " + date1);

        ZoneId id = ZoneId.of("Europe/Paris");
        System.out.println("ZoneId: " + id);

        ZoneId currentZone = ZoneId.systemDefault();
        System.out.println("当期时区: " + currentZone);
    }
}
